-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a ProducerConsumer helper for processing a sequence of items in parallel. #73323
Conversation
@@ -222,23 +222,20 @@ private static bool IsHostOrRemoteWorkspace(Project project) | |||
|
|||
// Defer to the ProducerConsumer. We're search the unreferenced projects in parallel. As we get results, we'll | |||
// add them to the 'allSymbolReferences' queue. If we get enough results, we'll cancel all the other work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view with whitespace off.
}), | ||
await ProducerConsumer<ImmutableArray<SymbolReference>>.RunParallelAsync( | ||
viableUnreferencedProjects, | ||
produceItems: static async (project, onItemsFound, args) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this form is much easier to understand (for me at least). instead of hte nested lambdas, you just pass hte single lambda. It will be called in parallel, passing a single item from "viableUnreferencedProjects", and teh callback to call when items are produced based on htat item.
{ | ||
return RunAsync( | ||
// We're running in parallel, so we def have multiple writers | ||
ProducerConsumerOptions.SingleReaderOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never mind, I can see clearly now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-D
@@ -42,21 +42,21 @@ internal static class ProducerConsumer<TItem> | |||
/// </summary> | |||
public static Task RunAsync<TArgs>( | |||
ProducerConsumerOptions options, | |||
Func<Action<TItem>, TArgs, Task> produceItems, | |||
Func<ImmutableArray<TItem>, TArgs, Task> consumeItems, | |||
Func<Action<TItem>, TArgs, CancellationToken, Task> produceItems, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like produceItems. It's the callback responsible for producing all the items. It will just do that by producing them and passing them to callback it itself is provided.
return RunAsync( | ||
// We're running in parallel, so we def have multiple writers | ||
ProducerConsumerOptions.SingleReaderOptions, | ||
produceItems: static (callback, args, cancellationToken) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have coffee! I can also extract into local functions on a follow-up if that's ok.
@@ -90,13 +90,13 @@ private static IEnumerable<T> Prioritize<T>(IEnumerable<T> items, Func<T, bool> | |||
/// </summary> | |||
private static Task PerformParallelSearchAsync<T>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can consider removing in follow up
@ToddGrun can I make those changes in follow-up? |
@jasonmalinowski For review when you get back. |
No description provided.